import { ApiProperty } from '@nestjs/swagger';
import { BeforeInsert, Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { UserClient } from '../../userClient/assets/userClient.entity';
import {
  Constant_Enum_Enum_CashBack_Status,
  Constant_Enum_Enum_CashBack_Way,
  Constant_Enum_Name_CashBack_Status,
  Constant_Enum_Name_CashBack_Way,
  IConstant_Enum_Type_CashBack_Status,
  IConstant_Enum_Type_CashBack_Way,
} from '@/common/constants/enum';

@Entity('cashback')
export class CashBack {
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '用户', type: () => UserClient })
  @ManyToOne(() => UserClient)
  userClient: UserClient;

  @Column({ type: 'float' })
  @ApiProperty({ type: 'float', description: '申请提现金额' })
  applyMoney: number;

  @Column()
  @ApiProperty({
    description: '打款方式' + Constant_Enum_Name_CashBack_Way,
    enum: Constant_Enum_Enum_CashBack_Way,
  })
  cashBackWay: IConstant_Enum_Type_CashBack_Way;

  @Column({ default: Constant_Enum_Enum_CashBack_Status.CashBack_Status_Transfering })
  @ApiProperty({
    default: Constant_Enum_Enum_CashBack_Status.CashBack_Status_Transfering,
    description: '打款状态' + Constant_Enum_Name_CashBack_Status,
    enum: Constant_Enum_Enum_CashBack_Status,
  })
  status: IConstant_Enum_Type_CashBack_Status;

  @Column()
  @ApiProperty({ description: '打款时间（2024-01-01 12:00:00形式）' })
  cashBackTime: string;

  @Column({ nullable: true })
  @ApiProperty({ description: '打款截图' })
  cashBackImg?: string;

  @Column({
    type: 'bigint',
    nullable: true,
  })
  @ApiProperty({ description: '创建时间' })
  createTime: number;

  @BeforeInsert()
  setCreateTime() {
    this.createTime = Math.floor(Date.now() / 1000); // 使用秒级时间戳
  }
}
